package cn.cai.pethome.dept.service.impl;

import cn.cai.pethome.base.utils.ResultBean;
import cn.cai.pethome.dept.domain.Department;
import cn.cai.pethome.dept.mapper.IDepartmentMapper;
import cn.cai.pethome.dept.query.DepartmentQuery;
import cn.cai.pethome.dept.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private IDepartmentMapper departmentMapper;


    @Override
    public ResultBean<Department> queryAll(DepartmentQuery query) {
        ResultBean<Department> ResultBean = new ResultBean<>();
        ResultBean.setTotal(departmentMapper.findCountAll(query));//查询总条数放入ResultBean中
        ResultBean.setPageList(departmentMapper.findAll(query));
        return ResultBean;
    }

    @Override
    public Department findById(Long id) {
        return departmentMapper.findById(id);
    }

    @Transactional
    @Override
    public void addDept(Department department) {
        departmentMapper.addDept(department);
    }

    @Transactional
    @Override
    public void updateDept(Department department) {
        departmentMapper.updateDept(department);
    }

    @Transactional
    @Override
    public void deleteById(Long id) {
        departmentMapper.deleteById(id);
    }
}
